package com.ctgu.project.controller;

import com.ctgu.project.service.BlogsService;
import com.ctgu.project.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName BlogsController
 * @Author Alex2
 * @Date 2025/2/27 17:30
 **/
@RestController
@RequestMapping("/api/blogs")
public class BlogsController {
    @Autowired
    private BlogsService blogsService;

    /**
     * @Author: Alex
     * @Description: 点赞
     */
    // http://localhost:8080/api/blogs/likes?userId=1&id=1
    @GetMapping("/likes")
    public ApiResult like(@RequestParam("userId") Integer userId, @RequestParam("id") Integer id) {
        return blogsService.likeById(userId, id);
    }

    /**
     * @Author: Alex
     * @Description: 获取头5个点赞者
     */
    // http://localhost:8080/api/blogs/getLikesLeaderBoardsById/1
    @GetMapping("/getLikesLeaderBoardsById/{id}")
    public ApiResult getLikesLeaderBoardsById(@PathVariable("id") Integer id) {
        return blogsService.getLikesLeaderBoardsById(id);
    }
}